import request from './request'
import { AxiosPromise } from 'axios'

// 获取网点人员及地址下拉数据
export function getNetworkEmpAddressPageSelect(data) {
  return request({
    url: '/networkSelect/getNetworkEmpAddressPageSelect',
    method: 'post',
    data,
  })
}

// 获取网点及地址下拉数据
export function getNetworkAddressPageSelect(data) {
  return request({
    url: '/networkSelect/getNetworkAddressPageSelect',
    method: 'post',
    data,
  })
}

/**
 * 获取仓库列表
 * @param data - 请求参数
 * @param data.page - 当面页码
 * @param data.limit - 每页显示数量
 * @param data.outStore - 仓库类型：false-内部仓库，true-外部仓库
 * @param data.outStoreType - 外部仓库类型：1-服务商仓库，2-工程师仓库，当is_out_store=true时生效
 * @param data.storeSearch - 仓库关键词搜索：仓库名称/仓库编码
 * @param data.userSearch - 仓库联系人关键词搜索：仓库联系人/手机号
 */
export function getListStore(
  data: StorageAPIRequest.GetStoreListParam,
): AxiosPromise<APIResponseList<WarehouseAPIResponse.StoreListItem>> {
  return request({
    url: '/store/getList',
    method: 'post',
    data,
  })
}

//批量修改允许或不允许负库存
export function canNegativeStock(data, canNegativeStock) {
  return request({
    url: '/store/canNegativeStock?canNegativeStock=' + canNegativeStock,
    method: 'put',
    data,
  })
}
//批量删除仓库
export function deleteStore(data) {
  return request({
    url: '/store/delete',
    method: 'DELETE',
    data,
  })
}
//批量启用或禁用仓库
export function disableStore(data, status) {
  return request({
    url: '/store/disable?status=' + status,
    method: 'put',
    data,
  })
}
// 根据仓库ID获取仓库详情修改
export function getDetailStore(id: string) {
  return request({
    url: `/store/getDetail/${id}`,
    method: 'get',
  })
}
// 新增或修改仓库
export function saveStore(data) {
  return request({
    url: `/store/save`,
    method: 'post',
    data,
  })
}
// 获取仓库列表本月的入-出库的数量
export function getListCurrentMothInWidthOutStoreQty() {
  return request({
    url: `/store/getListCurrentMothInWidthOutStoreQty`,
    method: 'get',
  })
}
// 根据仓库ID获取仓库库存明细
export function getStoreDetailGoodsList(data, id: string) {
  return request({
    url: `/store/getStoreDetailGoodsList/` + id,
    method: 'post',
    data,
  })
}
// 根据仓库ID获取仓位列表
export function getStorePositionList(data, id: string) {
  return request({
    url: `/store/getStorePositionList/` + id,
    method: 'post',
    data,
  })
}
// 根据仓位ID获取仓位库存明细
export function getStorePositionDetailGoodsList(data, id: string) {
  return request({
    url: `/store/getStorePositionDetailGoodsList/` + id,
    method: 'post',
    data,
  })
}
// 设置
// 获取仓库类型列表
export function getStoreTypeList(data) {
  return request({
    url: `/store/type/getList`,
    method: 'post',
    data,
  })
}
// 新增或修改仓库类型
export function addStoreType(data) {
  return request({
    url: `/store/type/save`,
    method: 'post',
    data,
  })
}
//批量删除仓库类型
export function deleteStoreType(data) {
  return request({
    url: '/store/type/delete',
    method: 'DELETE',
    data,
  })
}
//批量启用或禁用仓库类型
export function disableStoreType(data, status) {
  return request({
    url: '/store/type/disable?status=' + status,
    method: 'put',
    data,
  })
}
// 根据仓库类型ID获取详情
export function getDetailStoreType(id: string) {
  return request({
    url: `/store/type/getDetail/${id}`,
    method: 'get',
  })
}

/**
 * 获取产品库存
 * @param {Object} data - 请求参数
 * @param {String} data.goodsId - 产品ID
 * @param {String} data.goodsSpecId - 产品规格ID
 * @param {String} data.storeId - 仓库ID
 * @param {String} data.storePositionId - 仓库仓位ID
 * @param {(1|2)} data.type - 产品类型：1-成品，2-物料
 */
export function getGoodsStock(
  data: StorageAPIRequest.GetWarehouseGoodStock,
): AxiosPromise<WarehouseOutAPIResponse.GoodStock> {
  return request({
    url: `/store/goods/stock/getGoodsStock`,
    method: 'post',
    data,
  })
}

/**
 * 仓库下拉列表查询
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键字
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 页码
 * @param {(0|1|2)} warehouseType - 仓库类型
 */
export function storePageSelect(
  data: { name: string; page: number; limit: number },
  warehouseType: 0 | 1 | 2,
): AxiosPromise<WarehouseOutAPIResponse.WarehouseOptionList> {
  return request({
    url: '/store/select/storePageSelect/' + warehouseType,
    method: 'post',
    data,
  })
}

/**
 * 根据仓库ID获取仓位下拉列表
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键字
 * @param {Number} data.limit - 一页显示多少条
 * @param {Object} data.page - 页码
 * @param storeId - 仓库id
 */
export function storePositionPageSelect(
  data: { name: string; limit: number; page: number },
  storeId: string,
): AxiosPromise<WarehouseOutAPIResponse.WarehousePositionOptionList> {
  return request({
    url: '/store/select/storePositionPageSelect/' + storeId,
    method: 'post',
    data,
  })
}

/**
 * 仓库及人员地址下拉列表查询
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键字
 * @param {Number} data.page - 页码
 * @param {Number} data.limit - 一页显示多少条
 * @param {(0|1|2)} storeType - 仓库类型：0-内部仓库，1-服务商-外部仓库，2-工程师-外部仓库
 */
export function storeEmpAddressPageSelect(
  data: { limit: number; page: number; name: string },
  storeType: 0 | 1 | 2,
): AxiosPromise<WarehouseOutAPIResponse.WarehouseAndPersonAddressList> {
  return request({
    url: '/store/select/storeEmpAddressPageSelect/' + storeType,
    method: 'post',
    data,
  })
}

/**
 * 获取出库列表
 * @param {StorageAPIRequest.GetWarehouseOutList} data - 请求参数
 * @param {'' | 1 | 2 | 3 | 4 | 5} data.dateType - 日期类型：1-时间区间，2-今天，3-本周，4-本月，5-过去在个月
 * @param {string} data.endTime - 结束时间
 * @param {number} data.limit - 	每页显示数量
 * @param {number} data.page - 当面页码
 * @param {string} data.search - 关键词搜索：出库单列表搜索支持：出库单号/收货人/收货人手机号/制单人；入库单列表搜索支持：出库单号/制单人
 * @param {'' | 1 | 2 | 3 | 4 | 5} data.source - 单据来源：1-系统单，2-工单，3-ERP单据，4-仓库移动端单据，5-第三方系统单据
 * @param {string} data.startTime - 开始时间
 * @param {'' | 1 | 2 | 3 | 4 | 5} data.status - 1-待审核，2-待出库/待发货，3-驳回，4-已完成/已出库，5-已作废/取消
 * @param {string} data.typeId - 出/入库类型ID
 * @returns {AxiosPromise<WarehouseOutAPIResponse.WarehouseOutList>} - 出库列表
 */
export function outboundList(
  data: StorageAPIRequest.GetWarehouseOutList,
): AxiosPromise<WarehouseOutAPIResponse.WarehouseOutList> {
  return request({
    url: '/store/outbound/getList',
    method: 'post',
    data,
  })
}

/**
 * 出库仓库类型下拉列表查询
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键字
 * @param {Number} data.limit - 每页显示多少条
 * @param {Number} data.page - 页码
 */
export function outStoreTypePageSelect(data: {
  limit: number
  page: number
  name: string
}): AxiosPromise<WarehouseOutAPIResponse.WarehouseTypeOptionList> {
  return request({
    url: '/store/select/outStoreTypePageSelect',
    method: 'post',
    data,
  })
}

/**
 * 根据出库单ID获取出库详情
 * @param id - 出库单id
 */
export function getOutboundDetail(
  id: string,
): AxiosPromise<WarehouseOutAPIResponse.DetailBeforeCheck> {
  return request({
    url: '/store/outbound/getOutboundDetail/' + id,
    method: 'get',
  })
}

/**
 * 根据出库单ID获取出库物料
 * @param id - 出库单id
 */
export function getOutboundMaterial(
  id: string,
): AxiosPromise<WarehouseOutAPIResponse.MaterialList> {
  return request({
    url: '/store/outbound/getOutboundMaterial/' + id,
    method: 'get',
  })
}

/**
 * 保存或审核出库单
 * @param {StorageAPIRequest.WarehouseOutFormSave} data - 请求参数
 * @param {(1|2)} submitType - 提交类型：1-保存，2-审核
 */
export function saveOrCheck(
  data: StorageAPIRequest.WarehouseOutFormSave,
  submitType: 1 | 2,
): AxiosPromise<APIResponse> {
  return request({
    url: '/store/outbound/saveOrCheck/' + submitType,
    method: 'post',
    data,
  })
}

// 作废出库单
export function cancelStoreOutbound(data, id: string) {
  return request({
    url: '/store/outbound/cancelStoreOutbound/' + id,
    method: 'post',
    data,
  })
}

/**
 * 获取在库的条码
 * @param {Object} data - 请求参数
 * @param {String} data.goodsId - 产品ID
 * @param {String} data.goodsSpecId - 产品规格ID
 * @param {String} data.keyword - 搜索关键词:条码
 * @param {Number} data.limit - 每页显示数量
 * @param {Number} data.page - 当面页码
 * @param {String} data.storeId - 仓库ID
 * @param {String} data.storePositionId - 仓库仓位ID
 * @param {(1|2)} data.type - 类型:1-成品,2-物料
 */
export function getInStoreCodeList(
  data: CodeAPIRequest.GetInWarehouseSnCodeList,
): AxiosPromise<WarehouseOutAPIResponse.InWarehouseSnCodeList> {
  return request({
    url: '/store/outbound/getInStoreCodeList',
    method: 'post',
    data,
  })
}

// 确认出库
export function saveSureStoreOutbound(data, id: string) {
  return request({
    url: '/store/outbound/saveSureStoreOutbound/' + id,
    method: 'post',
    data,
  })
}

/**
 * 获取出入库产品
 * @param {StorageAPIRequest.GetWarehouseOutGoodList} data - 请求参数
 * @param {(1|2)} type - 产品类型：1-成品，2-物料
 */
export function getInOrOutStoreGoods(
  data: StorageAPIRequest.GetWarehouseOutGoodList,
  type: 1 | 2,
): AxiosPromise<WarehouseOutAPIResponse.GoodList> {
  return request({
    url: `/goods/product/getInOrOutStoreGoods/${type}`,
    method: 'post',
    data,
  })
}

/**
 * 根据入库单ID获取入库单详情
 * @param {String} id 入库单id
 */
export function getInboundDetail(id: string): AxiosPromise<WarehouseEntryAPIResponse.Detail> {
  return request({
    url: '/store/inbound/getInboundDetail/' + id,
    method: 'get',
  })
}

/**
 * 根据入库单ID获取入库单详情物料
 * @param {String} id - 入库单id
 */
export function getInboundDetailMaterial(
  id: string,
): AxiosPromise<WarehouseEntryAPIResponse.DetailGoodList> {
  return request({
    url: '/store/inbound/getInboundDetailMaterial/' + id,
    method: 'get',
  })
}

/**
 * 获取入库列表
 * @param {Object} data - 请求参数
 */
export function inboundList(
  data: StorageAPIRequest.GetWarehouseInListParam,
): AxiosPromise<WarehouseEntryAPIResponse.List> {
  return request({
    url: '/store/inbound/getList',
    method: 'post',
    data,
  })
}

// 获取未出入库的条码
export function getStoreCodeList(data) {
  return request({
    url: '/store/inbound/getStoreCodeList',
    method: 'post',
    data,
  })
}
// 保存或保存并审核入库单
export function saveinboundCheck(data, submitType): AxiosPromise<APIResponse> {
  return request({
    url: '/store/inbound/save/' + submitType,
    method: 'post',
    data,
  })
}

//确认入库
export function saveSureStoreInbound(data, id: string) {
  return request({
    url: '/store/inbound/saveSureStoreOutbound/' + id,
    method: 'post',
    data,
  })
}

/**
 * 入库仓库类型下拉列表查询
 * @param {Object} data - 请求参数
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 页码
 * @param {String} data.name - 搜索关键字
 */
export function inStoreTypePageSelect(data: {
  name: string
  limit: number
  page: number
}): AxiosPromise<WarehouseEntryAPIResponse.DocumentTypeOptions> {
  return request({
    url: '/store/select/inStoreTypePageSelect',
    method: 'post',
    data,
  })
}

//获取物流下拉列表
export function getLogisticsSelectList(data) {
  return request({
    url: '/system/logistics/getLogisticsSelectList',
    method: 'post',
    data,
  })
}

/**
 * 获取出库收货公司信息
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键字
 * @param {Number} data.page - 页码
 * @param {Number} data.limit - 一页显示多少条
 */
export function getOutStoreReceiptsUser(data: {
  limit: number
  page: number
  name: string
}): AxiosPromise<WarehouseOutAPIResponse.ReceiptCustomerList> {
  return request({
    url: '/store/outbound/getOutStoreReceiptsUser',
    method: 'post',
    data,
  })
}

/**
 * 驳回出库单
 * @param {Object} data - 驳回表单
 * @param {String} data.remark - 驳回备注
 * @param {String} id - 出库单id
 */
export function rejectOutbound(data: { remark: string }, id: string): AxiosPromise<APIResponse> {
  return request({
    url: '/store/outbound/rejectOutbound/' + id,
    method: 'post',
    data,
  })
}

/**
 * 驳回入库单
 * @param {Object} data - 驳回表单
 * @param {String} data.remark - 驳回备注
 * @param {String} id - 入库单id
 */
export function rejectInbound(data: { remark: string }, id: string): AxiosPromise<APIResponse> {
  return request({
    url: '/store/inbound/rejectInbound/' + id,
    method: 'post',
    data,
  })
}

// 作废入库单
export function cancelStoreInbound(data, id: string) {
  return request({
    url: '/store/inbound/cancelStoreInbound/' + id,
    method: 'post',
    data,
  })
}
/**库存查询列表 */
export function getStockList(data) {
  return request({
    url: '/store/store/getStockList',
    method: 'post',
    data,
  })
}

/**
 * 获取仓库下拉数据
 * @param {Object} data - 请求参数
 * @param {number} data.limit - 每页显示数量
 * @param {number} data.page - 当面页码
 * @param {string} data.name - 搜索关键词
 * @param {string} data.id - ID搜索
 */
export function getStorePageSelect(data: {
  limit: number
  page: number
  name: string
  id: string
}): AxiosPromise<WarehouseAPIResponse.WarehouseOptionList> {
  return request({
    url: '/store/select/getStorePageSelect',
    method: 'post',
    data,
  })
}

/**
 * 获取网点仓库
 * @param id - 网点id
 */
export const getNetworkWarehouse = (
  id: string,
): AxiosPromise<WarehouseAPIResponse.WarehouseInfoByNetworkId> => {
  return request({
    url: `/store/getNetworkStore/${id}`,
    method: 'get',
  })
}

/**
 * 旧件退库-分页
 * @param params - 查询数据
 */
export const inboundOldPage = (params) => {
  return request({
    url: `/store/inbound/old/spare/page`,
    method: 'get',
    params,
  })
}

/**
 * 旧件退库-详情
 * @param id - id
 */
export const inboundOldDetail = (id) => {
  return request({
    url: `/store/inbound/old/spare/getById/${id}`,
    method: 'get',
  })
}

/**
 * 旧件退库-批量审核
 * @param data - ids
 */
export const udpateApplyByIds = (data) => {
  return request({
    url: `/store/inbound/old/spare/udpateApplyByIds`,
    method: 'post',
    data,
  })
}

/**
 * 旧件退库-批量修改物流信息
 * @param {StorageAPIRequest.OldPartMultipleReturn} data - 请求参数
 * @param {Array<string>} data.ids - id 列表
 * @param {string} data.logisticsCode - 物流公司单号
 * @param {string} data.logisticsCorpName - 物流公司
 */
export const updateLogisticsByIds = (
  data: StorageAPIRequest.OldPartMultipleReturn,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/store/inbound/old/spare/updateLogisticsByIds`,
    method: 'post',
    data,
  })
}

/**
 * 旧件退库-批量收货
 * @param data - ids
 */
export const updateOrderState = (data) => {
  return request({
    url: `/store/inbound/old/spare/updateOrderState`,
    method: 'post',
    data,
  })
}

/**
 * 批量反写工单物料出库单到星空的其他出库单
 * @param {Array<string>} idList - 出库单ID集合
 */
export const warehouseOutWriteBack = (idList: Array<string>): AxiosPromise<APIResponse> => {
  return request({
    url: '/store/outbound/writeBackWorkMaterialOutbound',
    method: 'post',
    data: idList,
  })
}

/**
 * 获取所有的仓库下拉选项
 * @param {Object} data - 请求参数
 * @param {string} data.id - ID搜索
 * @param {number} data.limit - 每页显示数量
 * @param {string} data.name - 搜索关键词
 * @param {number} data.page - 当面页码
 */
export const getAllWarehouseOptionList = (data: {
  id: string
  limit: number
  page: number
  name: string
}): AxiosPromise<WarehouseAPIResponse.AllWarehouseOptionList> => {
  return request({
    url: '/store/select/getAllStore',
    method: 'post',
    data,
  })
}

/**
 * 创建配件申请单
 * @param data - 请求参数
 * @param data.id - 主健ID, 为空则新增，不为空则更新
 * @param data.code - 申请单编号
 * @param data.networkId - 收货网点id:总部建单时传，不传默认为当前登录网点
 * @param data.type - 单据类型: 1-收费销售订单, 2-免费销售订单, 3-免费销售订单(完全赠送)
 * @param data.status - 状态：1-保存, 2-保存并提交
 * @param data.receivingStoreId - 收货仓id
 * @param data.shippingStoreId - 发货仓id
 * @param data.contactName - 联系人姓名
 * @param data.contactPhone - 联系人电话
 * @param data.orderRemark - 单据备注
 * @param data.address - 收货地址
 * @param data.detailAddress - 详细地址
 * @param data.createType - 建单类型：1-经销商建单， 2-总部建单
 * @param data.materialApplyParamList - 申请物料
 */
export const createSparePartApply = (
  data: StorageAPIRequest.SparePartApplyForm,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/spareApplyOrder/save',
    method: 'post',
    data,
  })
}

/**
 * 提交申请时校验库存以及单据类型
 * @param data - 请求参数
 * @param data.materialQty - 物料编码,申请数量
 * @param data.networkId - 收货网点id:总部操作时传，经销商操作时不传
 */
export const createSparePartApplyCheckStock = (data: {
  materialQty: Record<string, number>
  networkId: string
}): AxiosPromise<APIResponse<{ isSufficient: 0 | 1; type: 1 | 2 | 3; difference: string }>> => {
  return request({
    url: '/spareApplyOrder/submitCheckQtyAndType',
    method: 'post',
    data,
  })
}

/**
 * 获取配件申请单列表
 * @param data - 请求参数
 * @param data.page - 当面页码
 * @param data.limit - 每页显示数量
 * @param data.code - 申请单编号
 * @param data.networkCode - 网点code
 * @param data.organizeId - 组织Id
 * @param data.networkName - 网点名称
 */
export const getSparePartApplyList = (
  data: StorageAPIRequest.GetSparePartApplyListParam,
): AxiosPromise<APIResponseList<WarehouseAPIResponse.SparePartApplyListItem>> => {
  return request({
    url: '/spareApplyOrder/getList',
    method: 'post',
    data,
  })
}

/**
 * 配件申请单审核前校验库存
 * @param sparePartApplyId - 配件申请单id
 */
export const checkStockForSparePartApplyCheck = (
  sparePartApplyId: string,
  data: Record<string, number>,
): AxiosPromise<APIResponse<{ codeIsSufficientMap: Record<string, number> }>> => {
  return request({
    url: `/spareApplyOrder/auditCheckQty/${sparePartApplyId}`,
    method: 'post',
    data,
  })
}

/**
 * 配件申请单审核通过
 * @param data - 请求参数
 * @param data.id - 申请单ID
 * @param data.codeIsSufficientMap - 物料编码,库存是否充足: 0-库存不足， 1-库存充足
 * @param data.warehouseMap - 物料编码，库存地址
 */
export const checkSparePartApplyForPass = (data: {
  codeIsSufficientMap: Record<string, number>
  id: string
  warehouseMap: Record<string, string>
  orderQtyMap: Record<string, number>
}): AxiosPromise<APIResponse> => {
  return request({
    url: '/spareApplyOrder/pass',
    method: 'post',
    data,
  })
}

/**
 * 配件申请单审核驳回
 * @param sparePartApplyId - 配件申请单id
 */
export const checkSparePartApplyForReject = (
  sparePartApplyId: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/spareApplyOrder/reject/${sparePartApplyId}`,
    method: 'post',
  })
}

/**
 * 删除配件申请单
 * @param data - 申请单id集合
 */
export const multipleDeleteSparePartApply = (data: Array<string>): AxiosPromise<APIResponse> => {
  return request({
    url: '/spareApplyOrder/deleteByIds',
    method: 'post',
    data,
  })
}

/**
 * 获取配件申请单详情（免登录）
 * @param id - 申请单id
 */
export const getSparePartApplyDetailNoLogin = (
  id: string,
): AxiosPromise<APIResponse<WarehouseAPIResponse.SparePartApplyDetail>> => {
  return request({
    url: `/spareApplyOrder/noLogin/getDetailById/${id}`,
    method: 'get',
  })
}

/**
 * 获取配件申请单详情（登录后调用的）
 * @param id - 申请单id
 */
export const getSparePartApplyDetailLogin = (
  id: string,
): AxiosPromise<APIResponse<WarehouseAPIResponse.SparePartApplyDetail>> => {
  return request({
    url: `/spareApplyOrder/getDetailById/${id}`,
    method: 'get',
  })
}

/**
 * 配件申请单反审核
 * @param id - 申请单id
 */
export const sparePartApplyReverseCheck = (id: string): AxiosPromise<APIResponse> => {
  return request({
    url: `/spareApplyOrder/antiAudit/${id}`,
    method: 'post',
  })
}

/**
 * 配件申请单过账
 * @param data - 请求参数
 * @param data.id - 主健ID
 * @param data.code - 申请单编号
 * @param data.networkName - 网点名称
 * @param data.factory - 工厂
 * @param data.status - 状态：1-待审核， 2-审核通过， 3-审核不通过
 * @param data.type - 单据类型: 1-收费销售订单, 2-免费销售订单, 3-免费销售订单(完全赠送)
 * @param data.receivingStoreId - 收货仓id
 * @param data.shippingStoreId - 发货仓id
 * @param data.contactName - 联系人姓名
 * @param data.contactPhone - 联系人电话
 * @param data.orderRemark - 单据备注
 * @param data.address - 收货地址
 * @param data.detailAddress - 详细地址
 * @param data.createType - 建单类型：1-经销商建单， 2-总部建单
 * @param data.createTime - 创建时间
 * @param data.updateTime - 修改时间
 * @param data.materialApplyVoList - 申请单物料
 * @param messageId - OA代办消息id
 */
export const sparePartApplyPosting = (
  data: StorageAPIRequest.SparePartApplyPostingForm,
  messageId: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/oa/posting/posting-sale-order/${messageId}`,
    method: 'post',
    data,
  })
}

/**
 * 配件申请单反过账
 * @param sparePartApplyId - 申请单id
 */
export const sparePartApplyReverse = (sparePartApplyId: string) => {
  return request({
    url: `/oa/posting/anti-posting-sale-order/${sparePartApplyId}`,
    method: 'post',
  })
}

/**
 * 调用API同步SAP条码信息
 * @param data - 请求参数
 * @param data.startDate - 开始日期
 * @param data.endDate - 结束日期
 * @param uuid - uuid
 */
export const syncSnCodeFromSAP = (
  data: {
    startDate: string
    endDate: string
  },
  uuid: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/chant-sap/code/syncCustom/${uuid}`,
    method: 'post',
    data,
  })
}

/**
 * 同步物料
 * @param data - 请求参数
 * @param data.startDate - 开始日期
 * @param data.endDate - 结束日期
 * @param uuid - uuid
 */
export const syncGoodListFromSAP = (
  data: {
    startDate: string
    endDate: string
  },
  uuid: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/chant-sap/goods/syncGoods/${uuid}`,
    method: 'post',
    data,
  })
}

/**
 * 同步客户
 * @param data - 请求参数
 * @param data.startDate - 开始日期
 * @param data.endDate - 结束日期
 * @param uuid - uuid
 */
export const syncCustomerFromSAP = (
  data: {
    startDate: string
    endDate: string
  },
  uuid: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/chant-sap/customs/syncCustom/${uuid}`,
    method: 'post',
    data,
  })
}

/**
 * 同步经销商出库含税金额
 * @param data - 请求参数
 * @param data.startDate - 开始日期
 * @param data.endDate - 结束日期
 * @param uuid - uuid
 */
export const syncSaleAmountFromSAP = (
  data: {
    startDate: string
    endDate: string
  },
  uuid: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/chant-sap/customs/syncCustomSale/${uuid}`,
    method: 'post',
    data,
  })
}

/**
 * 配件申请单审批通过
 * @param taskId - 流程id
 * @param nodeInstanceId - 节点id
 * @param key - 关键字
 */
export const applySparePartApprovePass = (
  taskId: string,
  key: string,
  nodeInstanceId: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/flow/approval/${taskId}/${key}/${nodeInstanceId}`,
    method: 'get',
  })
}

/**
 * 配件申请单审批拒绝
 * @param taskId - 流程id
 * @param nodeInstanceId - 节点id
 * @param key - 关键字
 */
export const applySparePartApproveReject = (
  taskId: string,
  key: string,
  nodeInstanceId: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/flow/reject/${taskId}/${key}/${nodeInstanceId}`,
    method: 'get',
  })
}
